package com.project.demo.service.impi;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.demo.entity.Water;
import com.project.demo.mapper.Watermapper;
import com.project.demo.service.WaterService;
import com.project.demo.vo.AllLandVo;
import com.project.demo.vo.AllWaterVo;
import com.project.demo.vo.LandVo;
import com.project.demo.vo.WaterVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class WaterServiceimpi implements WaterService {
    @Autowired
    private Watermapper watermapper;

    @Override
    public WaterVo<AllWaterVo> FindWaterVo(Integer page, Integer limit) {
        WaterVo waterVo = new WaterVo();
        waterVo.setCode(0);
        waterVo.setMsg("");
        IPage<Water> waterIPage = new Page<>(page,limit);
        IPage<Water>result =  watermapper.selectPage(waterIPage,null);
        waterVo.setCount(result.getTotal());
        List<Water> waterList = result.getRecords();
        List<AllWaterVo> allLandVoList = new ArrayList<>();
        for (Water water1 : waterList){
            AllWaterVo allWaterVo = new AllWaterVo();
            BeanUtils.copyProperties(water1,allWaterVo);
            allLandVoList.add(allWaterVo);
        }
        waterVo.setData(allLandVoList);
        return waterVo;
    }



    @Override
    public  WaterVo<AllWaterVo> FindAllWaterVo() {
        WaterVo waterVo = new WaterVo();
        waterVo.setCode(0);
        waterVo.setMsg("");
        waterVo.setCount(Long.valueOf(watermapper.selectCount(null)));
        List<Water>waterList = watermapper.selectList(null);
        List<AllWaterVo> allLandVoList = new ArrayList<>();
        for (Water water1 : waterList){
            AllWaterVo allWaterVo = new AllWaterVo();
            BeanUtils.copyProperties(water1,allWaterVo);
            allLandVoList.add(allWaterVo);
        }
        waterVo.setData(allLandVoList);
        return waterVo;
    }

    @Override
    public Integer deleteVo(Integer name) {
        return watermapper.deleteVo(name);
    }
    @Override
    public Integer insertVo(String liuyu, Integer username,String kuname,
                            Integer rongliang,Integer xushui,Integer dayaverge,
                            Integer dayhigh,Integer maxfall,Integer hole)
    {
        return watermapper.insertVo(liuyu,username,kuname,rongliang,xushui,dayaverge,dayhigh,maxfall,hole);
    }
}
